import { trim, ajax } from '../../helper/helper';
import { workflowListData, allUsers, historyData } from '../static/index';

const workflowListRenderData = function (dispatch, params) {
    // ajax({
    //     type: 'GET',
    //     url: '/teamUser/list',
    //     data: {
    //         page: params.page,
    //         size: params.size,
    //         cmd: 'teamUser'
    //     },
    //     success: function(data) {
    //         try {
    //             data = JSON.parse(data);
    //         } catch (error) {

    //         }
    //         if(data.success) {
    //             dispatch({
    //                 type: 'user-list-render-data',
    //                 val: data.result
    //             });
    //         }
    //     }
    // });

    setTimeout(function () {
        dispatch({
            type: 'workflow-list-render-data',
            val: workflowListData
        });
    }, 100);
}

const workflowListSetPageIndex = function (dispatch, params) {
    let PageIndex = params.skip / params.limit;
    params.currentPageIndex = PageIndex;
    params.targetPageIndex = PageIndex;
    dispatch({
        type: 'workflow-list-set-setPageIndex',
        val: PageIndex
    })
}

const workflowListRequest = function (dispatch, params) {
    dispatch({
        type: 'workflow-list-request',
        val: params
    })
}


const historyListRenderData = function (dispatch, params) {
    // ajax({
    //     type: 'GET',
    //     url: '/teamUser/list',
    //     data: {
    //         page: params.page,
    //         size: params.size,
    //         cmd: 'teamUser'
    //     },
    //     success: function(data) {
    //         try {
    //             data = JSON.parse(data);
    //         } catch (error) {

    //         }
    //         if(data.success) {
    //             dispatch({
    //                 type: 'user-list-render-data',
    //                 val: data.result
    //             });
    //         }
    //     }
    // });

    setTimeout(function () {
        dispatch({
            type: 'history-list-render-data',
            val: historyData
        });
    }, 100);
}

const historyListSetPageIndex = function (dispatch, params) {
    let PageIndex = params.skip / params.limit;
    params.currentPageIndex = PageIndex;
    params.targetPageIndex = PageIndex;
    dispatch({
        type: 'history-list-set-setPageIndex',
        val: PageIndex
    })
}

const historyListRequest = function (dispatch, params) {
    dispatch({
        type: 'history-list-request',
        val: params
    })
}




export const actions = {
    workflowListRenderData: workflowListRenderData,
    workflowListSetPageIndex: workflowListSetPageIndex,
    workflowListRequest: workflowListRequest,
    historyListRenderData: historyListRenderData,
    historyListSetPageIndex: historyListSetPageIndex,
    historyListRequest: historyListRequest,


}